// pages/article/article.js

const app = getApp();
var api = require('../../api.js');
var mta = require('../../mta_analysis.js');
let WxParse = require('../../wxParse/wxParse.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    mta.Page.init();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var page = this ;
    wx.getNetworkType({
      success: function (res) {
        console.log(res)
        page.setData({
          networkType: res.networkType
        })
      }
    });
    page.getDetail();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },

  // 获取详情
  getDetail: function () {

    var that = this;

    var access_token = wx.getStorageSync('access_token');
    wx.request({
      url: api.userdd.articles,
      method: "get",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        access_token: access_token,
        id:1
      },

      success: function (res) {
        console.log(res);

        if (res.data.code == 0) {
          console.log(res.data.data);
          var article = res.data.data;
          that.setData({
            article: article
          })
          console.log(article);
          // console.log(article.indexOf("<"))
          var temp = WxParse.wxParse('article', 'html', article, that, 5);
          // if (article.indexOf("<") != -1) {
          //   that.setData({
          //     judge: false
          //   })
          //   var temp = WxParse.wxParse('article', 'html', article, that, 5);
          // } else {
          //   that.setData({
          //     judge: true
          //   })

          // }
        }
        

      }
    });
  }
})